<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>9、props简写</title>
</head>
<body>
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 对props属性类型，以及是否必传进行限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    
    <script type="text/babel">
        class Person extends React.Component{
            render(){
                const {name,gender,age} = this.props
                return (
                    <ul>
                        <li>姓名：{name}</li>
                        <li>性别：{gender}</li>
                        <li>年龄：{age}</li>
                    </ul>
                )
            }
            static propTypes = {
                name: PropTypes.string.isRequired,
                gender: PropTypes.string,
                age: PropTypes.number,
                speak: PropTypes.func
            }

            static defaultProps = {
                gender: '人妖',
                age: 18
            }
        }
        const p = {name:'Jack', gender:'男',age:16}

        function speak(){
            console.log("说话");
        }

        ReactDOM.render(<Person {...p} />, document.getElementById('test1'))
        ReactDOM.render(<Person name="Mary" speak={speak}/>, document.getElementById('test2'))
        ReactDOM.render(<Person name="Bob" gender="男" age={17} />, document.getElementById('test3'))
    </script>
</body>
</html>